<template>
  <base-modal
    :title="initData.pageType === 'edit' ? ' 编辑授课记录' : ' 添加授课记录'"
    cancelText="取消"
    okText="保存"
    :width="900"
    :visible.sync="visible"
    @cancel="cancel"
    @ok="handleOk"
    :maskClosable="false"
  >
    <a-form-model
      ref="form"
      :model="formInfo"
      :rules="rules"
      :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
      :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
    >
      <a-row>
        <a-col span="24">
          <a-form-model-item label="课题名称" prop="name">
            <BaseInput placeholder="请输入" v-model.trim="formInfo.name" />
          </a-form-model-item>
        </a-col>
        <a-col span="24">
          <a-form-model-item label="授众" prop="audience">
            <BaseTextarea placeholder="请输入" v-model.trim="formInfo.audience" />
          </a-form-model-item>
        </a-col>
        <a-col span="12">
          <a-form-model-item label="授课时间" prop="teachingTime">
            <a-date-picker value-format="YYYY-MM-DD" placeholder="请选择" v-model="formInfo.teachingTime" />
          </a-form-model-item>
        </a-col>
        <a-col span="12">
          <a-form-model-item label="时长（小时）" prop="duration">
            <BaseInputNumber placeholder="请输入" v-model.trim="formInfo.duration" />
          </a-form-model-item>
        </a-col>
        <a-col span="24">
          <a-form-model-item label="备注" prop="remarks">
            <BaseTextarea placeholder="请输入" v-model.trim="formInfo.remarks" />
          </a-form-model-item>
        </a-col>
        <a-col span="24">
          <a-form-model-item label="附件">
            <upload-list
              :businessCode="'SHE09'"
              :uploadArrys.sync="formInfo.fileInfoList"
              multiple
            ></upload-list>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </base-modal>
</template>

<script>
import BaseModal from '@/components/BaseModal'
import UploadList from '@/components/UploadList'

export default {
  name: 'a' + Date.now(),
  components: {
    BaseModal,
    UploadList
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    initData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  watch: {
    visible(e) {
      this.formInfo = this.$clone(this.initData)
    }
  },
  data() {
    return {
      formInfo: {},
      rules: {
        name: [{ required: true, message: '请输入', trigger: 'change' }],
        audience: [{ required: true, message: '请输入', trigger: 'change' }],
        duration: [{ required: true, message: '请输入', trigger: 'change' }],
        remarks: [{ required: true, message: '请输入', trigger: 'change' }],
        teachingTime: [{ required: true, message: '请选择', trigger: 'change' }]
      }
    }
  },
  methods: {
    async handleOk() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit('confirm', this.formInfo)
          this.cancel()
        } else {
          this.$noticeWarning('请填写完整')
        }
      })
    },
    cancel() {
      this.$refs.form.clearValidate()
      this.$emit('update:visible', false)
    }
  }
}
</script>